/*
 * Directory.h
 *
 *  Created on: 26/06/2014
 *      Author: Vitor
 */

#ifndef DIRECTORY_H_
#define DIRECTORY_H_

#include <vector>
#include <string>
#include <stdlib.h>
#include "FileSystemElement.h"
#include "FileDescriptor.h"

class Directory: public FileSystemElement {
private:
	std::vector<FileSystemElement*> children;
	Directory* parent;

	void add_element(FileSystemElement* element) {
		children.insert(children.end(), element);
	}

public:
	Directory(std::string name, Directory* parent);
	virtual ~Directory();

	void add_directory(Directory* directory) {
		add_element(directory);
	}

	void add_file(FileDescriptor* file) {
		add_element(file);
	}

	void delete_element(std::string path) {
		for (auto it = children.begin(); it != children.end(); it++) {
			if ((*it)->get_name() == path) {
				delete (*it);
				children.erase(it);
				return;
			}
		}
	}

	void rename(std::string old_full_path, std::string new_full_path);

	void print() {
		printf("Diretorio: %s\n", name.c_str());
		for (auto& child : children) {
			child->print();
		}
	}

	FileSystemElement* get_element_from_path(std::string path);

	std::string html_encoding();
	std::string html_children_encoding();

	ByteQueue serialize();
};

#endif /* DIRECTORY_H_ */
